import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 38917
 * Date: 2025-02-09
 * Time: 20:01
 */
public class MyStack {
    private int[] elem;
    private int usedSize;
    private static final int DEFAULT_CAPACITY = 10;

     public MyStack(){
         this.elem = new int[DEFAULT_CAPACITY];
     }

     public void push(int data){
         if (isFull()){
             elem = Arrays.copyOf(elem,elem.length*2);
         }
         elem[usedSize] = data;
         usedSize++;
     }

     public Boolean isFull(){
         return usedSize == elem.length;
     }

     public int pop(){
         if (isEmpty()){
             throw new Exception("空指针异常");
         }
         int oldData = elem[usedSize-1];
         usedSize--;
         return oldData;
     }

     public int peek(){
         if (isEmpty()){
             throw new Exception("空指针异常");
         }
         return elem[usedSize-1];
     }

     public Boolean isEmpty(){
         return usedSize == 0;
     }
}